package com.af.robot.util;

import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

public abstract class Manager {

    public abstract  boolean start(String path);

    public abstract boolean stop(String condition);

    public boolean isLive(String url){
        try {
            HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
            httpRequestFactory.setConnectionRequestTimeout(2000);
            httpRequestFactory.setConnectTimeout(2000);
            httpRequestFactory.setReadTimeout(2000);
            ResponseEntity<String> forEntity = new RestTemplate(httpRequestFactory).getForEntity(url, String.class);
            return forEntity.getStatusCodeValue() == 200;
        } catch (Exception e){
            return false;
        }
    }
}
